import useAxiosApi from '/@/utils/useAxiosApi';
import axios from "axios";
import { useUserStore } from "/src/store/modules/user";

/**
 * 获取信息
 * @returns UseAxiosReturn
 */
export function getFreeTestInfo(userId) {
    return useAxiosApi('/hbmy_wx/sport.freeTestQuery', {
        method: 'POST',
        data: { stuid: userId },
    });
}

/**
 * 发起申请
 * @returns UseAxiosReturn
 */
export function applyFreeTest(userId,number) {
    return useAxiosApi('/hbmy_wx/sport.freeTestApply', {
        method: 'POST',
        data: { stuid: userId, number},
    });
}



/**
 * 更新申请
 * @returns UseAxiosReturn
 */
export function updateFreeTest(userId,state,reason) {
    return useAxiosApi('/hbmy_wx/sport.freeTestUpdate', {
        method: 'POST',
        data: { stuid: userId,state,reason },
    });
}

/**
 * 添加文件
 * @returns UseAxiosReturn
 */
export function addFreeTestFile(file,stuid,theYear) {
    const param = new FormData();
    param.append("file", file.file);
    param.append("stuid", stuid);
    param.append("theYear", theYear);

    const useUser = useUserStore()

    const config = {
        headers: { "Content-Type": "multipart/form-data","token":useUser.getUserToken }
    };
    return axios.post('/hbmy_wx/upload.file', param, config);
    //1\
    // const param = new FormData();
    // param.append("file", file);
    //
    // const config = {
    //     headers: { "Content-Type": "multipart/form-data" }
    // };
    // this.$axios.post("/upload", param, config).then(res => {
    //     console.log(res);
    // });
    // const param = new FormData();
    // param.append("file", file);
    // param.append("stuid", stuid);
    // param.append("theYear", theYear);
    //2\
    // const formData = new window.FormData();
    // formData.append("file", file);
    // formData.append("stuid", stuid);
    // formData.append("theYear", theYear);
    // console.log('formData:',formData)
    // return useAxiosApi('/api/upload.file', {
    //     method: 'POST',
    //     formData
    //     // env: {'multipart/form-data'},
    //     // maxBodyLength: 1232896000,
    //     // headers: {
    //     // //为了不进行预处理请求需要用这种格式的数据
    //     //     'Content-Type': 'multipart/form-data;'
    //     // },
    //     // params: formData,
    //     // params: {file,stuid,theYear},
    //     // data: {file,stuid,theYear},
    //     // env: {FormData: formData},
    // });
}

/**
 * 删除文件
 * @returns UseAxiosReturn
 */
export function delTestFile(stuid,theYear,fileId,diskName) {
    console.log("@@@")
    return useAxiosApi('/hbmy_wx/file.delete', {
        method: 'POST',
        data: { stuid,theYear,id:fileId,diskName},
    });
}


/**
 * 提交申请
 * @returns UseAxiosReturn
 */
export function pushFreeTest(userId,reason) {
    return useAxiosApi('/hbmy_wx/sport.freeTestUpdate', {
        method: 'POST',
        data: { stuid: userId,state: 2,reason },
    });
}

